08. Challenge: Changing Tire Size

Unfortunately, Carla's tires (like any car's tires), don't always stay exactly the same size. When the outside temperature changes, the diameter of the tires will change too. This uncertainty shows up everywhere in self driving cars. One way to deal with it is through exploration of your environment.

For Carla, that could mean doing the following every time she "wakes up":

  1. Measure the distance between herself and an object directly behind her.
  2. Turn her wheels exactly one full rotation.
  3. Make the same distance measurement again.
  4. Use the measurements from 1 and 3 to calculate the distance traveled. This is the current circumference of her tires.
  5. Perform the appropriate math to compute the current diameter of her tires.

Unfortunately, Carla has a bug in the code that performs steps 4 and 5! Help Carla drive by finding and fixing the bug!

Note: If you aren't ready to program in Python yet, that's okay! You can skip this quiz and the quiz in Challenge: Shortest Path for now; we'll provide you some resources to brush up on Python in the next lesson (as well as going through a lot of additional Python techniques throughout the Nanodegree program).

Start Quiz:

from math import pi

def get_tire_diameter(dist_before_turn, dist_after_turn):
    
    # TODO - there's a bug in this function! Find and fix it!
    
    circumference = dist_after_turn - dist_before_turn
    diameter = circumference * pi
    return diameter

User's Answer:

(Note: The answer done by the user is not guaranteed to be correct)

from math import pi

def get_tire_diameter(dist_before_turn, dist_after_turn):
    
    # TODO - there's a bug in this function! Find and fix it!
    
    circumference = dist_after_turn - dist_before_turn
    diameter = circumference / pi
    return diameter